package com.bm.specialvehiclefordispatcher.activity.welcome;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import cn.jpush.android.api.JPushInterface;

import com.bm.corelibs.utils.SharedPreferencesUtil;
import com.bm.specialvehiclefordispatcher.R;
import com.bm.specialvehiclefordispatcher.activity.BaseActivity;
import com.bm.specialvehiclefordispatcher.activity.main.MainActivity;
import com.bm.specialvehiclefordispatcher.constants.Constant;

/**
 * @author guoh 引导页
 * 
 */
public class WelcomeActivity extends BaseActivity {
	/** Called when the activity is first created. */

	Context context = WelcomeActivity.this;
	SharedPreferencesUtil sp;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_welcome);
		findViews();
		init();
		addListeners();
	}

	public void StartApp() {

		SharedPreferencesUtil spu = new SharedPreferencesUtil(WelcomeActivity.this, "SV");

		// 如果不是第一次
		if (spu.getStringByKey(Constant.IS_FIRST_KEY).equals("1")) {
			Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
			startActivity(intent);
		} else {
			// 第一次启动
			// 进入到注册页面
			spu.saveString(Constant.IS_FIRST_KEY, "1");
			Intent intent = new Intent();
			intent.setClass(WelcomeActivity.this, GuidancePagerActivity.class);
			startActivity(intent);
		}
		finish();
	}

	@Override
	public void findViews() {

	}

	@Override
	public void init() {
		mHandler.postDelayed(new Runnable() {
			@Override
			public void run() {
				StartApp();
			}
		}, 2000);
	}

//	private Runnable failRunnable = new Runnable() {
//
//		@Override
//		public void run() {
//			StartApp();
//			ToastMgr.show("定位失败");
//		}
//	};

	@Override
	public void addListeners() {
	}
	
	@Override
	protected void onResume() {
		JPushInterface.onResume(WelcomeActivity.this);
		super.onResume();
	}
	
	@Override
	protected void onPause() {
		JPushInterface.onPause(WelcomeActivity.this);
		super.onPause();
	}

}